home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / circuits / spice2g6.z / spice2g6 / spice / unix.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-07-07  |  6.0 KB  |  366 lines

  1. /*
  2.  * SCCSID=unix.c 3/15/83
  3.  */
  4.  
  5. #include <sys/param.h>
  6. #include <stdio.h>
  7. #include <time.h>
  8.  
  9. #ifndef BSD
  10. #    define bcopy(s, d, l) memcpy(d, s, l)
  11. #    define bzero(b, l) memset(b, 0, l)
  12. #endif
  13.  
  14.  
  15. #ifdef mips
  16. #    define xargc f77argc
  17. #    define xargv f77argv
  18. #endif
  19.  
  20. extern    int    xargc;
  21. extern    char    **xargv;
  22.  
  23.  
  24. /*
  25.  * loc_ - return the address of arg
  26.  */
  27. int
  28. loc_( arg )
  29.     int *arg;
  30. {
  31.     return( (int) arg );
  32. }
  33.  
  34.  
  35. /*
  36.  * times_ - c routine to call library routine times
  37.  */
  38. void
  39. times_( iarg )
  40.     int *iarg ;
  41. {
  42.     times( iarg );
  43. }
  44.  
  45. /*
  46.  * xtime_ - fortran routine for character time
  47.  */
  48. void
  49. xtime_( chr )
  50.     char *chr;
  51. {
  52.     struct tm    *localtime();
  53.     char        *asctime(),    *character;
  54.     long        time();
  55.     long        tloc,    scum;
  56.     int        i;
  57.  
  58.         tloc = time( & scum );
  59.         character = asctime( localtime(& tloc) );
  60.         for( i = 11; i < 19; i++ )
  61.                 *chr++ = *( character + i );
  62. }
  63.  
  64. /*
  65.  * xdate_ - fortran routine for character date
  66.  */
  67. void
  68. xdate_( chr )
  69.     char    *chr;
  70. {
  71.     struct    tm    *localtime(),    *buffer;
  72.     char        *asctime(),    *month,    *day,    *year,    *itoc();
  73.     long        time();
  74.     long        tloc,    scum;
  75.  
  76.         tloc = time( & scum );
  77.         buffer = localtime( & tloc);
  78.         month = itoc( buffer->tm_mon + 1 );   /* month is zero based */
  79.         while( *month )
  80.                 *chr++ = *month++;
  81.         *chr++ = '\/';
  82.         day = itoc( buffer->tm_mday );
  83.         while( *day )
  84.                 *chr++ = *day++;
  85.         *chr++ = '\/';
  86.         year = itoc( buffer->tm_year );
  87.         while( *year )
  88.                 *chr++ = *year++;
  89. }
  90.  
  91. /*
  92.  * itoc
  93.  */
  94. static char  *
  95. itoc( number )
  96.     int    number;
  97. {
  98.     static char string[3];
  99.  
  100.     /*
  101.      * make a two digit string from the least significant digits of number
  102.      */
  103.         string[2] = '\0';
  104.         string[1] = number%10 + '0';
  105.         number /= 10;
  106.         string[0] = number%10 + '0';
  107.         return( string );
  108. }
  109.  
  110. /*
  111.  * dblsgl - convert a complex double precision array into
  112.  *  a single precision complex array.
  113.  */
  114. void
  115. dblsgl_( cstar16, numwds )
  116.     double    *cstar16;
  117.     int    *numwds;
  118. {
  119. #if 0
  120.     float    *cstar8;
  121.     int    i;
  122.  
  123.     cstar8 = (float *) cstar16;
  124.     for ( i = 0; i < (*numwds)/4; i++ ) {
  125.         cstar8[ i ] = cstar16[ 2*i ];
  126.     }
  127. #endif
  128. }
  129.  
  130. static FILE *rawfile;  /* pointer to raw file  */
  131.  
  132. /*
  133.  * Open raw data file.  Return 1 if file is opened,
  134.  *  return 0 if file is not opened
  135.  */
  136. int
  137. iopraw_()
  138. {
  139.     int    i;
  140.     char    *filename = NULL;/* name of raw file */
  141.  
  142.     for ( i=1; i < xargc; i++ ) {
  143.         if ( *xargv[i] == '-' )
  144.             switch ( xargv[i][1] )  {
  145.             case 'r':
  146.                 if ( ++i < xargc )
  147.                     filename = xargv[i];
  148.                 else
  149.                     filename = "rawspice";
  150.                 break;
  151.             default:
  152.                 fprintf( stderr, "SPICE: illegal option -%c - ignored\n",
  153.                         xargv[i][1] );
  154.                 break;
  155.             }
  156.     }
  157.     if ( filename == NULL )
  158.         return( 0 );
  159.     if  ( (rawfile=fopen( filename, "w" )) == NULL ) {
  160.         fprintf( stderr, "SPICE: unable to open file %s\n", filename );
  161.         fprintf( stderr, "SPICE:  *** program terminated ***\n" );
  162.         exit( 1 );  /* terminate program */
  163.     }
  164.     return( 1 );  /* normal termination */
  165. }
  166.  
  167. /*
  168.  * Close raw file.
  169.  */
  170. void
  171. clsraw_()
  172. {
  173.     fclose( rawfile );
  174. }
  175.  
  176. /*
  177.  * Write into raw file numwds 16 bit words starting
  178.  *  at location data
  179.  */
  180. void
  181. fwrite_( data, numwds )
  182.     char    *data;
  183.     int    *numwds;
  184. {
  185.     fflush( stderr );
  186.     fwrite( data, 2, *numwds, rawfile );
  187.     fflush( rawfile );
  188. }
  189.  
  190. static void mcopy();
  191.  
  192. /*
  193.  * Zero, copy and move for vax unix.
  194.  */
  195. void
  196. move_( array1, index1, array2, index2, length )
  197.     register char    *array1, *array2;
  198.     register int    *length;
  199.     int        *index1, *index2;
  200. {
  201.     array1 += *index1 - 1;
  202.     array2 += *index2 - 1;
  203.     mcopy( array2, array1, *length );
  204. }
  205.  
  206.  
  207. void
  208. zero4_( array, length )
  209.     char        *array;
  210.     unsigned    *length;
  211. {
  212.     bzero( array, *length * 4 );
  213. }
  214.  
  215.  
  216. void
  217. zero8_( array, length )
  218.     char        *array;
  219.     unsigned    *length;
  220. {
  221.     bzero( array, *length * 8 );
  222. }
  223.  
  224.  
  225. void
  226. zero16_( array, length )
  227.     char        *array;
  228.     unsigned    *length;
  229. {
  230.     bzero( array, *length * 8 );
  231. }
  232.  
  233.  
  234. void
  235. copy4_( from, to, length )
  236.     char        *from, *to;
  237.     int        *length;
  238. {
  239.     mcopy( from, to, *length * 4 );
  240. }
  241.  
  242.  
  243. void
  244. copy8_( from, to, length )
  245.     char        *from, *to;
  246.     int        *length;
  247. {
  248.     mcopy( from, to, *length * 8 );
  249. }
  250.  
  251.  
  252. void
  253. copy16_( from, to, length )
  254.     char        *from, *to;
  255.     int        *length;
  256. {
  257.     mcopy( from, to, *length * 8 );
  258. }
  259.  
  260.  
  261.  
  262. #ifdef vax
  263.  
  264. #define VAXMAXSIZE ((2<<15) - 1);
  265.  
  266. /*
  267.  * mcopy - copy memory.
  268.  */
  269. static void
  270. mcopy( from, to, size )
  271.     char        *from,    *to;
  272.     int        size;
  273. {
  274.     register int        i = VAXMAXSIZE;
  275.  
  276.     if ( size < i ) {
  277.         asm( "    movc3 12(ap),*4(ap),*8(ap)" );
  278.         return;
  279.     }
  280.     else if ( from >= to ) {
  281.         for ( ; size > i; size -= i, to += i, from += i ) {
  282.             asm( "    movc3 r11,*4(ap),*8(ap)" );
  283.         }
  284.         asm( "    movc3 12(ap),*4(ap),*8(ap)" );
  285.         return;
  286.     }
  287.     else {
  288.         to   += size;
  289.         from += size;
  290.         size -= i;
  291.         for ( ; size > 0; size -= i ) {
  292.             to   -= i;
  293.             from -= i;
  294.             asm( "    movc3 r11,*4(ap),*8(ap)" );
  295.         }
  296.         size += i;
  297.         to   -= size;
  298.         from -= size;
  299.         asm( "    movc3 12(ap),*4(ap),*8(ap)" );
  300.         return;
  301.     }
  302. }
  303.  
  304. #else
  305.  
  306. /*
  307.  * mcopy - copy memory.
  308.  */
  309. static void
  310. mcopy (from, to, size)
  311.     register char *from, *to;
  312.     register int size;
  313. {
  314.     register char *frome, *toe;
  315.  
  316.     if (size <= 0) return;
  317.  
  318.     frome = from + size;
  319.     if (from >= to || frome <= to) {
  320.     bcopy (from, to, size);
  321.     }
  322.     else {
  323.     /* Source and destination overlap with destination above source.
  324.        Therefore a forward copy will bash later source to be copied.
  325.        Use a backward copy instead. */
  326.     toe = to + size;
  327.     if ((((unsigned)to ^ (unsigned)from) & 3) != 0 || size < 4) {
  328.         /* alignment of source and destination not identical;
  329.            use a simple byte copy. */
  330.         do {
  331.         *--toe = *--frome;
  332.         } while (frome != from);
  333.     }
  334.     else {
  335.         while (((unsigned)toe & 3) != 0) {
  336.         *--toe = *--frome;
  337.         size -= 1;
  338.         }
  339.         size -= 16;
  340.         while (size >= 0) {
  341.         toe -= 16;
  342.         frome -= 16;
  343.         ((int*)toe)[3] = ((int*)frome)[3];
  344.         ((int*)toe)[2] = ((int*)frome)[2];
  345.         ((int*)toe)[1] = ((int*)frome)[1];
  346.         ((int*)toe)[0] = ((int*)frome)[0];
  347.         size -= 16;
  348.         }
  349.         size += 16 - 4;
  350.         while (size >= 0) {
  351.         toe -= 4;
  352.         frome -= 4;
  353.         ((int*)toe)[0] = ((int*)frome)[0];
  354.         size -= 4;
  355.         }
  356.         size += 4;
  357.         while (size > 0) {
  358.         *--toe = *--frome;
  359.         size -= 1;
  360.         }
  361.     }
  362.     }
  363. }
  364. #endif
  365.  
  366.